package com.dingwei.superiordiary.mvp.presenter;

import android.text.TextUtils;

import com.dingwei.superiordiary.base.MyBaseBean;
import com.dingwei.superiordiary.bean.FailsBean;
import com.dingwei.superiordiary.bean.SafeSetBean;
import com.dingwei.superiordiary.bean.UserDataBean;
import com.dingwei.superiordiary.custom.myCallback;
import com.dingwei.superiordiary.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.base.URLS;
import com.lihao.baselibrary.base.basePresenter;

import org.xutils.http.RequestParams;
import org.xutils.x;

/**
 * @author Li Hao
 *         Created by lihao on 2017/9/12.
 */

public class SafeSetPresenter extends basePresenter {

    private Contract.SafeSetView safeSetView;

    public SafeSetPresenter(Contract.SafeSetView view) {
        super(view);
        this.safeSetView = view;
    }

    public void initData() {
        RequestParams rp = new RequestParams(URLS.HOST + URLS.security);
        rp.addBodyParameter("sessionid", BaseActivity.value.getToken());
        x.http().post(rp, new myCallback(BaseActivity.context, SafeSetBean.class, rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                SafeSetBean bean = (SafeSetBean) baseBean;
                safeSetView.setData(bean);
            }

            @Override
            public void fail(FailsBean baseBean, String result) {
                safeSetView.onFail();
            }
        });
    }





    public void WXlogin(final String type, final String uid) {
        final RequestParams rp = new RequestParams(URLS.HOST + URLS.EDIT_USER_DATA);
        rp.addBodyParameter("sessionid", BaseActivity.value.getToken());
        switch (type) {
            case "QQ":
                rp.addBodyParameter("bind_qq",uid);
                break;
            case "WEIXIN":
                rp.addBodyParameter("bind_wx",uid);
                break;
        }
        x.http().post(rp, new myCallback(BaseActivity.context, MyBaseBean.class, rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                switch (type) {
                    case "QQ":
                        if (TextUtils.isEmpty(uid)){
                            safeSetView.unbindQQSuccess();
                        }else {
                            safeSetView.bindQQSuccess();
                        }
                        break;
                    case "WEIXIN":
                        if (TextUtils.isEmpty(uid)){
                            safeSetView.unbindWXSuccess();
                        }else {
                            safeSetView.bindWXSuccess();
                        }

                        break;
                }
            }

            @Override
            public void fail(FailsBean baseBean, String result) {
            }
        });
    }
}
